$(function () {
	$('.search-bar .dropdown-menu a').click(function () {
		var field = $(this).data('field') || '';
		$('#search-field').val(field);
		$('#search-btn').html($(this).text() + ' <span class="caret"></span>');
	});
});
$(document).ready(function (e) {
	// 使用时，请自行引入jquery.cookie.js
	// 读取cookie中的主题设置
	var the_logo_bg = $.cookie('the_logo_bg'),
			the_header_bg = $.cookie('the_header_bg'),
			the_sidebar_bg = $.cookie('the_sidebar_bg'), // iframe版本如果删除了下面一行，请把这一行的逗号改成分号
			the_site_theme = $.cookie('the_site_theme'); // iframe版本可不需要这行
	
	if (the_logo_bg) $('body').attr('data-logobg', the_logo_bg);
	if (the_header_bg) $('body').attr('data-headerbg', the_header_bg);
	if (the_sidebar_bg) $('body').attr('data-sidebarbg', the_sidebar_bg);
	if (the_site_theme) $('body').attr('data-theme', the_site_theme); // iframe版本可不需要这行
	
	// 处理主题配色下拉选中
	$(".dropdown-skin :radio").each(function () {
		var $this = $(this),
				radioName = $this.attr('name');
		switch (radioName) {
			case 'site_theme':
				$this.val() == the_site_theme && $this.prop("checked", true);
				break;  // iframe版中不需要这个case
			case 'logo_bg':
				$this.val() == the_logo_bg && $this.prop("checked", true);
				break;
			case 'header_bg':
				$this.val() == the_header_bg && $this.prop("checked", true);
				break;
			case 'sidebar_bg':
				$this.val() == the_sidebar_bg && $this.prop("checked", true);
		}
	});
	
	// 设置主题配色
	setTheme = function (input_name, data_name) {
		$("input[name='" + input_name + "']").click(function () {
			$('body').attr(data_name, $(this).val());
			$.cookie('the_' + input_name, $(this).val(),{
				path:"/"
			});
		});
	}
	setTheme('site_theme', 'data-theme'); // iframe版本可不需要这行
	setTheme('logo_bg', 'data-logobg');
	setTheme('header_bg', 'data-headerbg');
	setTheme('sidebar_bg', 'data-sidebarbg');
});
//解析日期类
function getdateAll(jsonDate) {
	var now = new Date(jsonDate),
			y = now.getFullYear(),
			m = now.getMonth() + 1,
			d = now.getDate();
	return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0,8);
};
function getdate(jsonDate) {
	var now = new Date(jsonDate),
			y = now.getFullYear(),
			m = now.getMonth() + 1,
			d = now.getDate();
	return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
};